using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Text;
using System.IO;

using Jamila2.CoreElements;
using Jamila2.Tools;

public class EmailGenerator : ManagerBase
{
    protected string SourceContent = "";
    private string mail_title = "";

    public string MailTitle
    {
        get
        {
            return this.mail_title;
        }
    }

    public EmailGenerator(string SourceFile, string LanguageID)
    {
        // get the file name
        string FileName = SourceFile + "-" + LanguageID + ".htm";

        // read the file
        using (StreamReader FileReader = new StreamReader(FileName, Encoding.UTF8))
        {
            SourceContent = FileReader.ReadToEnd();
            FileReader.Close();
        }

    }

    #region GenerateReminderClaimForApprover
    public string GenerateReminderClaimForApprover(string ClaimID, string Reminder)
    {
        StringBuilder EmailBuilder = new StringBuilder(this.SourceContent);

        if (this.SourceContent.Length > 0)
        {
            // replace with data
            EmailBuilder.Replace("#ClaimID#", ClaimID);
            EmailBuilder.Replace("#Reminder#", Reminder);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
            this.mail_title = this.mail_title.Replace("#ClaimID#", ClaimID);
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateReminderClaimForApprover] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion

    #region GenerateReminderClaimForClaimant
    public string GenerateReminderClaimForClaimant(string ClaimID, string Reminder)
    {
        StringBuilder EmailBuilder = new StringBuilder();

        if (this.SourceContent.Length > 0)
        {
            EmailBuilder.Append(this.SourceContent);

            // replace with data
            EmailBuilder.Replace("#ClaimID#", ClaimID);
            EmailBuilder.Replace("#Reminder#", Reminder);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
            this.mail_title = this.mail_title.Replace("#ClaimID#", ClaimID);
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateReminderClaimForClaimant] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion

    #region GenerateMissingInfoAlert
    public string GenerateMissingInfoAlert(string EmployeeName, string EmployeeID)
    {
        StringBuilder EmailBuilder = new StringBuilder(this.SourceContent);

        if (this.SourceContent.Length > 0)
        {
            // replace with data
            EmailBuilder.Replace("#EmployeeName#", EmployeeName);
            EmailBuilder.Replace("#EmployeeID#", EmployeeID);

            // title
            this.mail_title = this.SourceContent.Substring(
                this.SourceContent.IndexOf("<title>") + "<title>".Length,
                this.SourceContent.IndexOf("</title>") - (this.SourceContent.IndexOf("<title>") + "<title>".Length));
        }
        else
        {
            this.ErrMsg = "[EmailGenerator.GenerateMissingInfoAlert] : No source file";
        }

        return EmailBuilder.ToString();
    }
    #endregion
}
